package com.liuxvru.project.system.controller;

import com.liuxvru.common.annotation.Log;
import com.liuxvru.common.core.controller.BaseController;
import com.liuxvru.common.core.domain.AjaxResult;
import com.liuxvru.common.core.page.TableDataInfo;
import com.liuxvru.common.enums.BusinessType;
import com.liuxvru.common.utils.poi.ExcelUtil;
import com.liuxvru.project.domain.TestStep;
import com.liuxvru.project.service.ITestStepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 测试明细Controller
 *
 * @author liuxvru
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/project/testStep")
public class TestStepController extends BaseController {
    @Autowired
    private ITestStepService testStepService;

    /**
     * 查询测试明细列表
     */
    @PreAuthorize("@ss.hasPermi('project:testStep:list')")
    @GetMapping("/list")
    public TableDataInfo list(TestStep testStep) {
        startPage();
        List<TestStep> list = testStepService.selectTestStepList(testStep);
        return getDataTable(list);
    }

    /**
     * 导出测试明细列表
     */
    @PreAuthorize("@ss.hasPermi('project:testStep:export')")
    @Log(title = "测试明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TestStep testStep) {
        List<TestStep> list = testStepService.selectTestStepList(testStep);
        ExcelUtil<TestStep> util = new ExcelUtil<TestStep>(TestStep.class);
        util.exportExcel(response, list, "测试明细数据");
    }

    /**
     * 获取测试明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:testStep:query')")
    @GetMapping(value = "/{stepId}")
    public AjaxResult getInfo(@PathVariable("stepId") Long stepId) {
        return success(testStepService.getById(stepId));
    }

    /**
     * 新增测试明细
     */
    @PreAuthorize("@ss.hasPermi('project:testStep:add')")
    @Log(title = "测试明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TestStep testStep) {
        return toAjax(testStepService.save(testStep));
    }

    /**
     * 修改测试明细
     */
    @PreAuthorize("@ss.hasPermi('project:testStep:edit')")
    @Log(title = "测试明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TestStep testStep) {
        return toAjax(testStepService.updateById(testStep));
    }

    /**
     * 删除测试明细
     */
    @PreAuthorize("@ss.hasPermi('project:testStep:remove')")
    @Log(title = "测试明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{stepIds}")
    public AjaxResult remove(@PathVariable Long[] stepIds) {
        return toAjax(testStepService.removeByIds(Arrays.asList(stepIds)));
    }
}
